package com.xr.wage.change;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.xr.common.CommUtil;

/**
 * datasetListener
 */
public class datasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	  String dsName = dataset.parameters().getString("dsName");
		String sql = "";
			SqlDataset ds = (SqlDataset) dataset;
			DoradoContext context = DoradoContext.getContext();
			 
			if(dsName != null && dsName.equals("onOffCwEmpList_datasetChangeList")) {
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
				 
			}
			if(dsName != null && dsName.equals("compareOperate_datasetCompareOperate")) {
				DBStatement dbs = new DBStatement();
				dbs.setSql("begin pck_wage.compare('" +ds.parameters().getString("SEND_MONTH")+"'); end;");
				dbs.execute();
				sql=ds.getSql();
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
			}
			if(dsName != null && dsName.equals("change_cwDetail_datasetCwdetail")) {
				sql=ds.getSql();
				
				if(dataset.parameters().getString("TYPE_ID")!=null&&!dataset.parameters().getString("TYPE_ID").equals("")){
					sql+=" and exists(select 1 from pb_hritems_type where hritems_id=cd.hritems_id and type_id="+dataset.parameters().getString("TYPE_ID")+")";
				}
				sql += CommUtil.setConditionSQL(ds)+" "; 
				ds.setSql(sql);
			}
			
			if(dsName != null && dsName.equals("sendNewModifyList_datasetList")) {
				//sql=ds.getSql();
				String cdn="",bt="",sql1="",sql2="",sql3="",sql4="",sql5="";
				bt=dataset.parameters().getString("BT");
				String[] bta= bt.split(",");
				for(int i=0;i<bta.length;i++){
					if(bta[i].equals("1")){
						sql1="";
					}
					
				}
				
				if(dataset.parameters().getString("TYPE_ID")!=null&&!dataset.parameters().getString("TYPE_ID").equals("")){
					sql+=" and exists(select 1 from pb_hritems_type where hritems_id=cd.hritems_id and type_id="+dataset.parameters().getString("TYPE_ID")+")";
				}
				 
				
				
				ds.setSql(sql);
			}
    return true;
  }

  public void afterLoadData(Dataset dataset)
     throws Exception {

  }

}
